package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/kataras/golog"
	model "sdn-executor/model/netconf"
	"sdn-executor/service"
	"sdn-executor/utils/erros"
)

func ExecuteNetconfCmd(c *gin.Context) {
	query := model.Query{}
	if err := c.ShouldBindJSON(&query); err != nil {
		SendResponse(c, erros.New(erros.CodeInvalidQueryParam, err.Error()), nil)
		return
	}

	response, err := service.ExecuteNetconfCmd(&query)
	if err != nil {
		golog.Error("doHandleNetconfRequest failed")
		SendResponse(c, err, nil)
		return
	}

	SendResponse(c, erros.OK, response)
}

func GetNetconfResultByRequestID(c *gin.Context) {
	requestId := c.Param("requestId")
	results, err := service.GetNetconfResultByRequestID(requestId)
	if err != nil {
		SendResponse(c, err, nil)
		return
	}
	SendResponse(c, erros.OK, results)
}
